<template>
    <el-container>
        <el-header>
            <el-container>
                <el-date-picker v-model="data.orderTimeList" format="yyyy-MM-dd" value-format="yyyy-MM-dd" type="daterange" align="right" unlink-panels range-separator="至" start-placeholder="预约开始日期" end-placeholder="预约结束日期" @change="(value) => handleChange(value || [], 'orderTimeList')" />
                <SearchInput placeholder="昵称、手机、客户名称" :change="(value) => handleChange(value, 'nicknameOrPhone')" />
                <BelongToSelect :change="(value) => handleChange(value, 'belongTo')" />
                <OrderStatusRadioGroup :change="(value) => handleChange(value, 'status')" />
                <SearchButton :click="search" />
            </el-container>
        </el-header>
        <el-main>
            <el-table :data="tableData" stripe element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)" v-loading.fullscreen.lock="loading">
                <el-table-column prop="orderId" label="订单编号" width="80" />
                <el-table-column prop="userId" label="用户编号" width="80" />
                <el-table-column prop="nick" label="昵称" width="80" />
                <el-table-column prop="username" label="客户名称" width="80" />
                <el-table-column prop="head" label="客户头像" width="120">
                    <template #="{ head }">
                        <Avatar :src="head" />
                    </template>
                </el-table-column>
                <el-table-column v-if="isShowPhone" prop="phone" label="手机号码" width="120" />
                <el-table-column prop="zsName" label="预约诊所" width="120" />
                <el-table-column prop="ysName" label="预约医生" width="80" />
                <el-table-column prop="orderTime" label="预约时间" width="100" />
                <el-table-column prop="belongTo" label="微信归属" width="100" />
                <el-table-column prop="orderAddr" label="预约的位置" min-width="80" />
                <el-table-column prop="inlet" label="预约入口" width="100" />
                <el-table-column prop="createTime" label="创建时间" width="100" />
                <el-table-column prop="status" label="状态" width="80">
                    <template #="{ status }">
                        <el-tag v-if="status == '0'">待预约</el-tag>
                        <el-tag v-if="status == '1'">已预约</el-tag>
                        <el-tag v-if="status == '4'">已取消</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="referrerNick" label="来源" width="80" />
                <el-table-column label="操作" width="180">
                    <template #="{ orderMu, status, orderTime }">
                        <UpdateOrderButton :hasCancle="status == '1'" :showUpdate="() => showUpdate(orderMu, orderTime)" :doCancel="() => doCancel(orderMu)" />
                    </template>
                </el-table-column>
            </el-table>
            <SearchPagination :currentPage="currentPage" :total="total" :limit="limit" @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange" />
        </el-main>
        <el-footer>
            <UpdateOrder :orderTime="orderTime" :change="(value) => (this.orderTime = value)" :showUpdateForm="showUpdateForm" :doUpdate="doUpdate" :hideUpdateForm="() => (this.showUpdateForm = false)" />
        </el-footer>
    </el-container>
</template>

<script>
import BelongToSelect from '@/app/components/BelongToSelect';
import OrderStatusRadioGroup from '@/app/components/order/OrderStatusRadioGroup';
import UpdateOrderButton from '@/app/components/order/UpdateOrderButton';
import UpdateOrder from '@/app/components/order/UpdateOrder';

import { page } from '@/chaos/functions/mixin/crud';
import { updateOrder } from '@/app/components/order/mixin/updateOrder';

export default {
    name: 'appointment',
    mixins: [page, updateOrder],
    components: {
        BelongToSelect,
        OrderStatusRadioGroup,
        UpdateOrderButton,
        UpdateOrder
    },
    data() {
        return {
            domain: 'iya_order',
            isShowPhone: true
        };
    },
    created() {
        const roleName = this.$store.getters.user.roleName;
        this.isShowPhone =
            roleName == 'ADMIN' || roleName == 'DEV' || roleName == 'OPII';
        this.searchMethod = 'orders';
        this.data.status = 1;
        this.search();
    }
};
</script>
<style scoped></style>
